package com.todo.user.application.backend.service.impl;

import com.todo.common.common.entity.response.page.PageResult;
import com.todo.user.application.backend.service.UserAccountBackendService;
import com.todo.user.application.convert.UserBackendConvert;
import com.todo.user.application.entity.bo.UserAccountBO;
import com.todo.user.application.entity.bo.UserAccountConditionBO;
import com.todo.user.application.entity.bo.UserInfoDetailBO;
import com.todo.user.application.service.UserAccountService;
import com.todo.user.application.service.UserInfoService;
import com.todo.user.common.enums.UserStatusEnum;
import com.todo.user.iface.backend.request.*;
import com.todo.user.iface.backend.response.QueryUserAccountByConditionResp;
import com.todo.user.iface.backend.response.UserAccountDetailResp;
import com.todo.user.iface.backend.response.UserAuthRecordResp;
import com.todo.user.iface.backend.response.UserOperateRecordResp;
import lombok.extern.slf4j.Slf4j;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * (UserAccount)表服务实现类
 *
 * @author zhangwenxiang
 * @since 2024-03-04 00:19:49
 */
@Slf4j
@Service("userAccountBackendService")
public class UserAccountBackendServiceImpl implements UserAccountBackendService {

    @Resource
    private UserAccountService userAccountService;
    @Resource
    private UserInfoService userInfoService;

    @Override
    public UserAccountDetailResp queryUserAccountDetail(QueryUserAccountDetailReq req) {
        if (req == null || req.getUserId() == null) {
            return null;
        }
        UserInfoDetailBO userInfoDetailBO = userInfoService.queryUserInfoDetailById(req.getUserId());
        UserAccountDetailResp resp = UserBackendConvert.convertToUserAccountDetailResp(userInfoDetailBO);
        return resp;
    }

    @Override
    public Boolean mutedUserAccount(MutedUserAccountReq req) {
        if (req == null || req.getUserId() == null) {
            return null;
        }
        Boolean result = userAccountService.mutedUserAccountById(req.getUserId(), UserStatusEnum.getByType(req.getStatus()), req.getReason());
        return result;
    }

    @Override
    public PageResult<QueryUserAccountByConditionResp> queryUserAccountByCondition(QueryUserAccountByConditionReq req) {
        if (req == null || !req.baseCheck()) {
            return PageResult.of(Lists.newArrayList(), 0, 0, 0);
        }
        UserAccountConditionBO conditionBO = UserBackendConvert.buildUserAccountConditionBO(req);
        PageResult<UserAccountBO> pageResult = userAccountService.queryUserAccountByCondition(conditionBO);
        return UserBackendConvert.convertToPageQueryUserAccount(pageResult);
    }

    @Override
    public PageResult<UserOperateRecordResp> queryUserOperateRecordByCondition(QueryUserOperateRecordByConditionReq req) {
        // TODO 当前没有详细的操作记录数据，暂时不做功能支持
        return null;
    }

    @Override
    public List<UserAuthRecordResp> queryUserAuthRecordList(QueryUserAuthRecordListReq req) {
        // TODO 当前先不做三方授权信息
        return Collections.emptyList();
    }
}
